/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：UPMProject
 *  文件：PackageInfoData.cs
 *  作者：Administrator
 *  日期：2025/7/25 18:0:56
 *  功能：Nothing
*************************************************************************/

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace SVNPackageManager.Runtime
{
    [System.Serializable]
    public class Author
    {
        public string name = "";
        public string email = "";
        public string url = "";
    }

    [System.Serializable]
    public class Sample
    {
        public string displayName;
        public string description;
        public string path;
    }

    [System.Serializable]
    public class Dependency
    {
        public string version;

        public string name;
    }

    /// <summary>
    /// 只用来作为面板上的显示需要的数据
    /// </summary>
    [System.Serializable]
    public class PackageConfig
    {
        public string name = "";
        public string version = "";
        public string displayName = "";
        public string description = "";
        public string documentationUrl = "";
        public string changelogUrl = "";
        public string licensesUrl = "";
        public string categoty = "";
        public List<Sample> samples = new List<Sample>();

        [JsonProperty("Dependencies")]
        public Dictionary<string, string> dependencies
        {
            set
            {
                foreach (var item in value)
                {
                    Dependencies.Add(new Dependency() { name = item.Key, version = item.Value });
                }
            }
        }

        [JsonIgnore]
        public List<Dependency> Dependencies = new List<Dependency>();
    }

    [System.Serializable]
    public class PackageSourceInfo
    {
        public string packageSourceName;
        public bool packageSourceFolderState;
        public List<PackageGroupInfo> packageGroupInfos;
    }

    [System.Serializable]
    public class PackageGroupInfo
    {
        public int groupIndex;  //允许多个同名的组存在
        public bool packageGroupFolderState;
        public string packageGroupID;
        public string installedPackageID;
        public string lastPackageID;
        public List<PackageItemInfo> packageInfos;

        public PackageItemInfo GetPackageItemInfo(string packageItemID)
        {
            return packageInfos.FirstOrDefault(item => item.packageItemID == packageItemID);
        }

        public PackageItemInfo GetInstalledPackageInfo()
        {
            return packageInfos.FirstOrDefault(item => item.isInstalled);
        }

        public PackageItemInfo GetLastPackageInfo()
        {
            return packageInfos.FirstOrDefault(item => item.isLast);
        }
    }

    [System.Serializable]
    public class PackageItemInfo
    {
        public string packageItemID;
        public string packageGroupID;
        public string packageSvnUrl;
        public string resolvedPath;
        public bool isInstalled;
        public bool isLast;
        public PackageConfig packageConfig;
    }
}


